from odoo import fields, models


class AgriTag(models.Model):
    _name = 'agri.tag'
    _description = '病虫害标签'
    _order = 'name'

    name = fields.Char(string='标签名称', required=True)
    usage = fields.Selection(
        selection=[
            ('disease', '病害'),
            ('pest', '虫害'),
            ('common', '通用'),
        ],
        string='适用范围',
        default='common',
    )
    color = fields.Integer(string='颜色')
    active = fields.Boolean(default=True)

    _sql_constraints = [
        ('name_usage_unique', 'unique(name, usage)', '同一类别下的标签名称必须唯一。'),
    ]

